package com.ebo.common.smart;

import cn.hutool.core.util.StrUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 地址数据加载器
 */
public interface AddressDataLoader {

    List<Address> loadData();

    default boolean provinceStartWith(String text) {
        List<Address> addresses = loadData();
        for (Address address : addresses) {
            // 获取简称
            String name = StrUtil.sub(address.getName(), 0, 2);
            if (text.startsWith(name)) {
                return true;
            }
        }
        return false;
    }



    @Data
    class Address {
        private String id;
        private String name;
        private String code;
        private Serializable parentId;
        private List<Address> children;
    }
}
